﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace PropertyManagementFeatures.FeatureCode
{
    class ViewingPromptTimerJob : SPJobDefinition 
    {

         public ViewingPromptTimerJob ()
             : base(){
          }


        public ViewingPromptTimerJob(string name, SPWebApplication applicaiton)
            :base (name, applicaiton, null, SPJobLockType.ContentDatabase){   
        }

        public override void Execute (Guid contentDbId) {
            
            SPWebApplication applicaiton = (SPWebApplication)this.Parent;
            SPContentDatabase contentDb = applicaiton.ContentDatabases[contentDbId];

            SPList list = contentDb.Sites[0].RootWeb.Lists["ViewingAppointments"];

            foreach (SPListItem item in list.Items)
            {
               
                DateTime startDate = DateTime.Parse(item["StartDate"].ToString());
                TimeSpan timeSpan = startDate.Subtract(DateTime.Now);

                if (timeSpan.Days < 2)
                {
                 
                    //Todo: Send email to vendor

                }
              

            }

        }

    }
}
